package com.itheima.stock.job;

import com.itheima.stock.service.StockTimerTasKService;
import com.xxl.job.core.handler.annotation.XxlJob;
import org.joda.time.DateTime;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Component;

/**
 * 定义xxljob任务执行器bean
 */
@Component
public class StockJob {
//    private static Logger logger = LoggerFactory.getLogger(SampleXxlJob.class);
    @Autowired
    private StockTimerTasKService stockTimerTasKService;


    /**
     * 1、简单任务示例（Bean模式）
     */
    @XxlJob("myJobHandler")
    public void demoJobHandler() throws Exception {
        System.out.println("当前时间点为："+ DateTime.now().toString("yyyy-MM-dd HH:mm:ss"));
//        XxlJobHelper.log("XXL-JOB, Hello World.");
//
//        for (int i = 0; i < 5; i++) {
//            XxlJobHelper.log("beat at:" + i);
//            TimeUnit.SECONDS.sleep(2);
//        }
        // default success
    }

    /**
     * 定时采集A股大盘数据
     * 建议针对不同的股票数据，定义不同的采集任务，解耦，方便维护
     */
    @XxlJob("getInnerMarketInfo")
    public void getStockInfos(){
        stockTimerTasKService.getInnerMarketInfo();
    }

    /**
     * 定时采集A股大盘个股数据
     */
    @XxlJob("getStockRtIndex")
    public void getStockRtIndex(){
        stockTimerTasKService.getStockRtIndex();
    }

    /**
     * 定时采集外股数据
     */
    @XxlJob("getOutMarketInfo")
    public void getOutMarketStockInfos(){
        stockTimerTasKService.getOuterMarketIndexInfo();
    }
}
